﻿using System.Collections.Generic;
using System.Xml.Serialization;
using System.Xml.Schema;
using System.Xml;
using System;

namespace FlickrSL.Data
{
    public class SizeCollection : Dictionary<SizeType, Size>, IXmlSerializable
    {
        static readonly XmlSerializer SizeSerializer = new XmlSerializer(typeof(Size));

        public XmlSchema GetSchema()
        {
            return null;
        }

        public void ReadXml(XmlReader reader)
        {
            reader.ReadStartElement("sizes");

            if (!reader.IsEmptyElement)
            {
                reader.MoveToContent();
                while (reader.NodeType != XmlNodeType.EndElement)
                {
                    Size s = (Size)SizeSerializer.Deserialize(reader);
                    this.Add(s.Type, s);

                    reader.MoveToContent();
                }
            }
            else
            {
                reader.Skip();
            }
        }

        public void WriteXml(XmlWriter writer)
        {
            throw new NotSupportedException();
        }
    }
}
